package net.comm.message.db;


import java.sql.ResultSet;
import java.sql.SQLException;


import net.comm.message.bean.BaseMessage;
import net.comm.util.StringUtil;

import org.apache.log4j.Logger;
import org.sakaiproject.db.api.SqlReader;

public class DbMessageService implements SqlReader
{

	static Logger logger = Logger.getLogger(DbMessageService.class.getName());

	/**
	 * Read from the result one set of fields to create a Resource.
	 * 
	 * @param result
	 *        The Sql query result.
	 * @return The Resource object.
	 */
	public Object readSqlResultRecord(ResultSet result)
	{
		try
		{
			
			int  	seqID = result.getInt(1);			//消息序号
			int  	receiver = result.getInt(2);		//接收用户ID
			int  	sender = result.getInt(3);			//发送用户ID
			String  sendertype = StringUtil.getValue(result.getString(4));	//发送用户类型
			int  	msgID = result.getInt(5);			//消息序号
			String  mtype = StringUtil.getValue(result.getString(6));		//消息类型
			String  title = StringUtil.getValue(result.getString(7));		//标题
			String  status = StringUtil.getValue(result.getString(8));		//接收方消息状态
			String  rTime = StringUtil.getValue(result.getString(9));		//阅读日期时间
			String  recvDelflg = StringUtil.getValue(result.getString(10));	//接收用户删除标志
			String  sndDelflg = StringUtil.getValue(result.getString(11));	//发送用户删除标志
			String  sTime = StringUtil.getValue(result.getString(12));		//发送日期时间
			String  mTime = StringUtil.getValue(result.getString(13));		//最后修改日期

			// create the Resource from these fields
			return new BaseMessage(  seqID, receiver,  sender,  sendertype,
					 msgID, mtype, title,  status,  rTime, recvDelflg,  sndDelflg,  sTime,  mTime );
		}
		catch (SQLException e)
		{
			logger.error("取记录失败！");
			return null;
		}
		
	}
}
